package leetCode;

public class t202m1 {
    public static void main(String[] args) {
        new SolutionS2().isHappy(19);
    }
}

class SolutionS2 {
    public int getNext(int i){
        int ret=0;
        while (i!=0){
            ret=ret+(i%10)*(i%10);
            i=i/10;
        }
        return ret;
    }
    public boolean isHappy(int n) {
        int low=n;
        int fast=n;
        do {
            low=getNext(low);
            fast=getNext(fast);
            fast=getNext(fast);
        }while (fast!=low);
        return low==1;
    }

}